package com.demo.controller;


import com.demo.domain.CtCar;
import com.demo.service.impl.CtCarServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CtCar)表控制层
 *
 * @author makejava
 * @since 2021-07-07 14:29:15
 */
@RestController
public class CtCarController {
    /**
     * 服务对象
     */
    @Resource
    private CtCarServiceImpl ctCarService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne1")
    public CtCar selectOne(Integer id) {
        return this.ctCarService.queryById(id);
    }
    @GetMapping("selectAll1")
    public List<CtCar> selectAll(){
        return this.ctCarService.queryAllByLimit();
    }
    @GetMapping("insertById1")
    public CtCar insertById(Integer type, String go_time, String start_area, String start_address, String end_area, String end_address, Integer person_num, String car_type, String car_number, Integer seat_num, String content, String person_name, String person_mobile){
        CtCar ctCar = new CtCar();
        if (type==1){
            ctCar.setCType(car_type);
            ctCar.setCNumber(car_number);
            ctCar.setCSite(seat_num);
            ctCar.setCCount(0);
        }else if (type==2){
            ctCar.setCType(null);
            ctCar.setCNumber(null);
            ctCar.setCSite(0);
            ctCar.setCCount(person_num);
        }
        System.out.println(go_time);
        ctCar.setCTime(go_time);
        ctCar.setCCity(start_area);
        ctCar.setCAttion(start_address);
        ctCar.setCTocity(end_area);
        ctCar.setCToattion(end_address);
        ctCar.setCContent(content);
        ctCar.setCPerson(person_name);
        ctCar.setCPhone(person_mobile);
        return this.ctCarService.insert(ctCar);
    }
    @PostMapping("updateById1")
    public CtCar updateById(CtCar ctCar){
        return this.ctCarService.update(ctCar);
    }
    @PostMapping("deleteById1/{id}")
    public boolean deleteById(@PathVariable int id){
        return this.ctCarService.deleteById(id);
    }
    @GetMapping("selectByCity")
    public List<CtCar> selectBtCity(String ctocity,String ccity){
        CtCar ctCar=new CtCar();
        ctCar.setCCity(ccity);
        ctCar.setCTocity(ctocity);
        return this.ctCarService.selectByCity(ctCar);
    }
}